/**
 * @filename:ScanServiceImpl Apr 3, 2024
 * @project Wonder Vue Admin Api  1.1.0
 * Copyright(c) 2022 Wonder Co. Ltd. 
 * All right reserved. 
 */
package com.wonder.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.wonder.app.domain.Proorder;
import com.wonder.app.domain.Scan;
import com.wonder.app.mapper.ScanDao;
import com.wonder.app.service.ScanService;
import com.wonder.app.request.ScanRequest;
import com.wonder.common.utils.DateUtils;
import com.wonder.common.utils.StringUtils;
import com.wonder.common.utils.MessageUtils;
import com.wonder.common.common.AjaxResult;

import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**   
 * @Description:TODO(追溯码服务实现)
 *
 * @version: 1.1.0
 * @author: Wonder
 * 
 */
@Service
public class ScanServiceImpl  extends ServiceImpl<ScanDao, Scan> implements ScanService  {

	@Autowired
	private ScanDao scanDao;

	@Autowired
	private ScanService scanService;
    /**
     * 验证追溯码信息
     * 
     * @param scan
     * @param type
     * @return String
     */
    @Override
    public String validate(Scan scan,String type){
    
    
       return "";
    }
    
    
    /**
	 * Description:追溯码分页返回
	 * @param request //检索条件
	 * @param page //分页参数
	 * @return IPage<Scan>   //分页记录
	 */
	@Override 
	public IPage<Scan> selectList(ScanRequest request, Page<Scan> page){
	    LambdaQueryWrapper<Scan> lambdaQueryWrapper = new LambdaQueryWrapper<>();
	    
	    if (null != request.getId()) {
	       lambdaQueryWrapper.eq(Scan::getId, request.getId());
	      }
	    if(null != request.getTrayNum()){
			lambdaQueryWrapper.like(Scan::getTrayNum,request.getTrayNum());
		}
		if(null != request.getTaskBillNo()){
			lambdaQueryWrapper.like(Scan::getTaskBillNo,request.getTaskBillNo());
		}
		if (request.getCreateTime() != null){
			Date[] createTime=request.getCreateTime();
			if(createTime.length>0)
				lambdaQueryWrapper.ge(Scan::getCreateTime, createTime[0]);
			if(createTime.length==2)
				lambdaQueryWrapper.le(Scan::getCreateTime, DateUtils.dateToStr(createTime[1],"yyyy-MM-dd") + " 23:59:59");

		}
		lambdaQueryWrapper.orderByDesc(Scan::getId);	
		Page<Scan> selectPage = this.baseMapper.selectPage(page, lambdaQueryWrapper);
		return selectPage;
    }

	@Override
	public Boolean binding(List<Long> idList, String taskBillNo) {
		UpdateWrapper<Scan> wrapper = new UpdateWrapper();
		wrapper.in("id",idList)
				.set("taskBillNo",taskBillNo);
		int update = scanDao.update(null, wrapper);
		if (update > 0){
			return true;
		} else {
			return false;
		}
	}


}